var common = require('../../utils/common.js');
const app = getApp()
Page({
  data: {
    windowHeight: app.globalData.windowHeight,
    code: '',

  },
  onLoad: function (options) {

  },
  inputWacth(e){
    console.log(e);
    this.setData({
      code: e.detail.value
    });
  },
  submit(){
    const that = this
    var code = this.data.code
    if (code == ''){
      wx.showToast({
        title: '请输入验证码',
        icon: 'none',
        duration: 2000
      })
    }else{
      common.post({
        url: '/app/user/inviteCode', data: { inviteCode: code, sessionId: app.globalData.sessionId }
      })
        .then((res) => {
          console.log(res.data)
          if (res.data.code == 0) {
            app.globalData.userInfo.needInviteCode = false
            // wx.reLaunch({
            //   url: '/pages/itemlist/itemlist',
            //   success: function (res) {
            //     console.log('toItemlist')
            //   },
            //   fail: function (res) {
            //     console.log(res)
            //   }
            // })
            if(app.globalData.thispath !== ''){
              wx.reLaunch({
                url: app.globalData.thispath,
                success(res){
                  console.log(res)
                },
                fail(res) {
                  console.log(res)
                }
              })
            }else{
              wx.reLaunch({
                url: app.globalData.path,
                success(res){
                  console.log(res)
                },
                fail(res) {
                  console.log(res)
                }
              })
            }
          } else {
            wx.showToast({
              title: res.data.errmsg,
              icon: 'none',
              duration: 2000
            })
          }
        }).catch((res) => {
          console.log(res)
        })
    }
  },
  noCode(){
    wx.showModal({
      title: '提示',
      content: '请联系身边已注册京多多的朋友索要或网络搜索京多多邀请码',
      confirmText: '知道了',
      showCancel: false,
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  agreement1(){
    wx.navigateTo({
      url: '/pages/agreement1/agreement1',
      success: function (res) {
        console.log('toAgreement1')
      },
      fail: function (res) {
        console.log(res)
      }
    })
  },
  agreement2(){
    wx.navigateTo({
      url: '/pages/agreement2/agreement2',
      success: function (res) {
        console.log('toAgreement2')
      },
      fail: function (res) {
        console.log(res)
      }
    })
  }
})